package com.song.oscsong.viewpagerfragment;

import com.song.oscsong.R;
import com.song.oscsong.adapter.ViewPageFragmentAdapter;
import com.song.oscsong.fragment.NewsFragment;
import com.song.oscsong.interf.OnTabReselectListener;
import com.song.oscsong.widget.PagerSlidingTabStrip;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

public class NewsViewPagerFragment extends Fragment implements OnTabReselectListener{
	
	
	private ViewPager mPager;
	private PagerSlidingTabStrip mTabStrip;
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		
		View v = inflater.inflate(R.layout.base_viewpage_fragment, container, false);
		
		mPager = (ViewPager)v.findViewById(R.id.pager);
		mTabStrip = (PagerSlidingTabStrip)v.findViewById(R.id.pager_tabstrip);
		InitViewPager();
		return v;
		
	}
	

	private void InitViewPager() {
		ViewPageFragmentAdapter adapter = new ViewPageFragmentAdapter(getChildFragmentManager(),mTabStrip ,  mPager);
		mPager.setAdapter(adapter);
		mTabStrip.setViewPager(mPager);
		onSetupTabAdapter(adapter);
	}





	private void onSetupTabAdapter(ViewPageFragmentAdapter adapter) {
		String[] titles = {"最新","每周","博客","意见"}; 
		
		adapter.addTab(titles[0],"news", NewsFragment.class, null);
		adapter.addTab(titles[1],"news_week", NewsFragment.class, null);
		adapter.addTab(titles[2],"latest_blog", NewsFragment.class, null);
		adapter.addTab(titles[3],"recommend_blog", NewsFragment.class, null);
		adapter.notifyDataSetChanged();
	}


	@Override
	public void OnTabReselect() {
		// TODO Auto-generated method stub
		
	}

	
	
	
}
